#include <iostream> 
using namespace std; 
int a[1000005]; 
int dp[100005];
int binarysearch(int x,int len) 
{ 
	int mid,left,right; 
	left=1; 
	right=len; 
	mid=(right+left)/2; 
	while(left<=right) 
	{ 
		if(x>dp[mid]) 
		{ 
			left=mid+1; 
		} 
		else 
			if(x<dp[mid]) 
			{ 
				right=mid-1; 
			} 
			else 
			{ 
				return mid; 
			} 
			mid=(right+left)/2; 
	} 
	return left; 
}

int main() 
{ 
	int i,j; 
	int len; 
	int n; 
	while(cin>>n) 
	{ 
		for(i=0;i<n;i++) 
		{ 
			cin>>a[i]; 
		} 
		dp[0]=-1000000; 
		dp[1]=a[0]; 
		len=1; 
		for(i=1;i<n;i++) 
		{ 
			j=binarysearch(a[i],len); 
			dp[j]=a[i]; 
			if(j>len) 
			{ 
				len=j; 
			} 
		} 
		cout<<len<<endl; 
	} 
	return 0; 
}
